<template>
    <div class="mine">
        <article>
            <div class="set">
                <img :src="require('@/assets/shop/mine/set.png')" alt="" @click="$router.push('/shop/infoEdit')" />
                <img :src="require('@/assets/shop/mine/tui.png')" @click="logout" alt="" />
            </div>
            <div class="head">
                <img :src="user_face($store.state.detail.user.pic)"  alt="" />
                <div>
                    <p class="name">{{$store.state.detail.user.name || '匿名用户'}}</p>
                    <p>

                        <span v-if="$store.state.detail.user.usercard =='' || $store.state.detail.user.usercard != null ">
                            {{ $store.state.detail.user.usercard}} </span>
                        <span v-if="$store.state.detail.user.usercard =='' || $store.state.detail.user.usercard == null ">
                            {{ $store.state.detail.user.login_name}} </span>
                        <span style="color:#FFFF00 ;" v-if="$store.state.detail.user.usergrade =='' || $store.state.detail.user.usergrade != null ">
                            &#160;
                            {{ $store.state.detail.user.usergrade}}会员</span>
                        <span style="color:#FFFF00 ;" v-if="$store.state.detail.user.shopgrade!=''">
                            &#160;
                            {{ $store.state.detail.user.shopgrade}}商家</span>
                    </p>

                </div>
            </div>
            <div class="tab">
                <ul>
                    <li @click="$router.push('/shop/car')">
                        <div>{{$store.state.detail.countAll>0?$store.state.detail.countAll:0}}</div>
                        <div>购物车</div>
                    </li>
                    <li @click="$router.push('/myCollection')">
                        <div>{{ $store.state.detail.user.collection}}</div>
                        <div>收藏</div>
                    </li>
                    <li @click="$router.push('/myBrowse')">
                        <div>{{ $store.state.detail.user.browse}}</div>
                        <div>足迹</div>
                    </li>
                    <li>
                        <div>0</div>
                        <div>红包券</div>
                    </li>
                </ul>
            </div>
            <div class="order">
                <div class="top">
                    <div class="title">我的订单</div>
                    <div class="all" @click="$router.push({name:'订单列表',params:{active: 0}})">
                        <span>全部订单 </span>
                        <img :src="require('@/assets/shop/mine/arrow.png')" alt="" />
                        <!-- state_pay  params: {state_pay: -1}-->
                    </div>
                </div>
                <ul>
                    <li @click="$router.push({name:'订单列表',params:{active: 1}})">
                        <img :src="require('@/assets/shop/mine/1.png')" style="width: 22px; height: 22px" alt="" />
                        <div>待付款</div>
                    </li>
                    <li @click="$router.push({name:'订单列表',params:{active: 2}})">
                        <img :src="require('@/assets/shop/mine/2.png')" style="width: 24px; height: 20px" alt="" />
                        <div>已付款</div>
                    </li>
                    <li @click="$router.push({name:'订单列表',params:{active: 3}})">
                        <img :src="require('@/assets/shop/mine/3.png')" style="width: 22px; height: 21px" alt="" />
                        <div>已完成</div>
                    </li>
                    <li>
                        <img :src="require('@/assets/shop/mine/4.png')" style="width: 20px; height: 22px" alt="" />
                        <div>退款/售后</div>
                    </li>
                </ul>
            </div>
        </article>
        <div class="info">
            <div class="title">Ta们在看</div>
            <van-swipe class="my-swipe" indicator-color="white" @change="onChange" style="height: 100px" vertical :show-indicators="false"
                :autoplay="3000">
                <van-swipe-item class="swipe_item" v-for="(k, index) in list" :key="index" @click="goDetails(k.c_id,k.type)">

                    <img v-lazy="checkPic(k.img)" alt="" class="bg" />
                    <section>
                        <div class="driver">
                            <p>
                                <span>{{ k.cname}}</span>

                            </p>
                            <p v-if="k.type==0">[特产]</p>
                            <p v-if="k.type==1">[目的地]</p>
                            <p v-if="k.type==2">[路线]</p>
                        </div>
                    </section>
                </van-swipe-item>

            </van-swipe>
        </div>

        <div class="service2">
            <div class="title">我的账户</div>
            <ul>
                <li>
                    <img :src="require('@/assets/shop/mine/account1.png')" style="width: 25px; height: 25px" alt="" />
                    <div>账号余额： <span>{{'￥'+$store.state.detail.user.rmb}}</span></div>
                </li>
                <li>
                    <img :src="require('@/assets/shop/mine/account2.png')" style="width: 25px; height: 25px" alt="" />
                    <div>剩余积分： <span>{{$store.state.detail.user.point+' 个'}}</span></div>
                </li>
            </ul>
        </div>

        <div class="service1">
            <div class="title">发布管理</div>
            <ul>
                <li @click="$router.push('/release_journey_list')">
                    <img :src="require('@/assets/shop/mine/sub1.png')" style="width: 26px; height: 19px" alt="" />
                    <div>线路</div>
                </li>
                <li v-if="this.$store.state.detail.user.SHOP_ID!=0" @click="shopOrder()">
                    <img :src="require('@/assets/shop/buy/shoporder.png')" style="width: 26px; height: 19px" alt="" />
                    <div>商品订单</div>
                </li>
                <li v-if="this.$store.state.detail.user.SHOP_ID!=0" @click="otherOrder(1506)">
                    <img :src="require('@/assets/shop/buy/canyin.png')" style="width: 26px; height: 19px" alt="" />
                    <div>餐饮订单</div>
                </li>
                <li v-if="this.$store.state.detail.user.SHOP_ID!=0" @click="otherOrder(1510)">
                    <img :src="require('@/assets/shop/buy/lvju.png')" style="width: 26px; height: 19px" alt="" />
                    <div>旅居订单</div>
                </li>
                <li v-if="this.$store.state.detail.user.SHOP_ID!=0" @click="otherOrder(1494)">
                    <img :src="require('@/assets/shop/buy/wanle.png')" style="width: 26px; height: 19px" alt="" />
                    <div>玩乐订单</div>
                </li>
                <li @click="$router.push('/myComment')">
                    <img :src="require('@/assets/shop/mine/sub2.png')" style="width: 25px; height: 25px" alt="" />
                    <div>评论</div>
                </li>
            </ul>
        </div>

        <div class="service">
            <div class="title">更多服务</div>
            <ul>
                <li @click="showList = true">
                    <img :src="require('@/assets/shop/mine/service1.png')" style="width: 19px; height: 23px" alt="" />
                    <div>地址管理</div>
                </li>
                <li>
                    <img :src="require('@/assets/shop/mine/service2.png')" style="width: 23px; height: 19px" alt="" />
                    <div>优惠券</div>
                </li>
                <!-- v-if="role_id==73" @click="$router.push('/userCode')" -->
                <!-- <li @click="$router.push('/userCode')">
          

                    <img :src="require('@/assets/shop/mine/service3.png')" style="width: 20px; height: 23px" alt="" />
                    <div>商家验票</div>

                </li> -->

                <li>
                    <a href="tel:0532-87849393">
                        <img :src="require('@/assets/shop/mine/service4.png')" style="width: 23px; height: 23px" alt="" />
                    </a>
                    <div>客户服务</div>
                </li>
                <li @click="$router.push('/myCollection')">
                    <img :src="require('@/assets/shop/mine/service5.png')" style="width: 23px; height: 23px" alt="" />
                    <div>我的收藏</div>
                </li>
            </ul>
        </div>

        <addressed :show="showList" @getMessage="changeShow"></addressed>
        <!-- 底部栏 -->
        <v-footer2></v-footer2>
    </div>
</template>
<script>
import "@/css/shop/mine.scss";
import Footer2 from "@/common/travel/_footer2.vue";
import addressed from "./address.vue"


export default {
    components: {
        "v-footer2": Footer2,
        addressed
    },
    data() {
        return {
            index: "",
            role_id: '',
            showList: false,
            list: [],
            domainUrl: this.$conf.domain,

        };
    },
    created() {
        let obj = { 'api_user': this.$store.state.login.username };
        this.$dopost('/sysapi/user/userinfo/', obj,
            function (response) {
                if (response.data && typeof (response.data.error) != "undefined" && response.data.error === 0) {
                    this.$store.state.detail.user = response.data.data;
                    this.role_id = response.data.data.role_id;
                    console.log(this.$store.state.detail.user, 1254)
                }
                else { Toast((response.data && response.data.mess) ? response.data.mess : '出错了！'); }
            }.bind(this), true);
        this.listpro();
    },
    methods: {
        listpro() {
            this.$dopost("/sysapi/user/indexbrowse/",
                {
                    api_user: this.$store.state.login.username,
                    viewloading: 0,
                    page: this.pageNum + 1,
                },
                function (res) {
                    if (
                        res.data &&
                        typeof res.data.error != "undefined" &&
                        res.data.error === 0
                    ) {

                        for (let i = 0; i < res.data.data.list.length; i++) {
                            this.list.push(res.data.data.list[i]);
                        }
                        this.pageNum = parseInt(res.data.data.page);

                        if (
                            parseInt(res.data.data.page) >= parseInt(res.data.data.allpage)
                        ) {
                            this.finished = true;
                        }
                        this.loading = false;

                    } else {
                        Toast(res.data && res.data.mess ? res.data.mess : "接口错误");
                    }
                }.bind(this)
            );


        },
        checkPic: function (picurl) {
            return this.$conf.domain + "/" + picurl;
        },
        otherOrder(i) {

            this.$router.push({ path: '/otherOrder', query: { sortId: i, shId: this.$store.state.detail.user.SHOP_ID } });
        },
        decodeURI(img) {
            var srcType = img.substring(0, 7)
            if (srcType == 'upload/') {
                return this.$conf.domain + "/" + img;
            } else {
                return img;
            }
        },
        shopOrder() {

            this.$router.push({ path: '/shopOrder', query: { shId: this.$store.state.detail.user.SHOP_ID } });
        },
        goDetails(c_id, type) {
            let url = '';
            if (type == 0) {
                //shop_new_detail
                url = "/shop/details";
            } else if (type == 1) {
                url = "/shop_new_detail";
            } else if (type == 2) {
                url = "/circuit_detail";
            }
            this.$router.push({ path: url, query: { id: c_id } });

        },
        // swiper切换
        onChange(index) {
            this.index = index;
        },
        changeShow(val) {
            this.showList = val
        },
        logout() {
            this.$dialog.confirm({
                title: '',
                message: '确定退出么？'
            }).then(() => {
                this.$store.commit('CHANGE_USER', 0, '', '');
                this.$router.replace({ path: '/login' });
            }).catch(() => {
                // on cancel
            });

        },
        user_face(url) {
            var index = url.indexOf("://")
            if (index == -1) {
                return this.domainUrl + '/' + url
            } else {
                return url
            }

        },

    },
};
</script>